stiko commented Jun 28, 2018
To reproduce, simply run:

<br>$docker run -d php:7.2-apache<br>$docker exec -ti <container_id> bash<br>$apache2 -t<br>

Result:
apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot

If you source /etc/apache2/envvars then restart apache, the container stops. Starting it will repeat the cycle.

Any one has a solution to this?

The php:apache images actually use apache-foreground to load the apache envvars file; and not apache2 directly (or apache2ctl since that would require an init system in the container).

Next time, look at the Dockerfile of the image to see what command and entrypoint it runs by default:

# https://github.com/docker-library/php/blob/b599d7375c12ff69e4d11ea10c3dea56dd670eb9/7.2/stretch/apache/Dockerfile#L257-L263
 
ENTRYPOINT ["docker-php-entrypoint"]
##<autogenerated>##
COPY apache2-foreground /usr/local/bin/
WORKDIR /var/www/html
 
EXPOSE 80
CMD ["apache2-foreground"]

You can find links to all the Dockerfiles for all versions of official images on their respective Docker Hub descriptions (and in this repo).